# -*- coding: utf-8 -*-
# @Time    : 2021/8/29 16:03
# @Author  : BrandonGT
# @FileName: code_03_event.py

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import sys
QObject
class App(QApplication):
    def notify(self, recevier, evt):  # recevier是QObject是对象，evt是QEvent是事件，注意区分类型
        if recevier.inherits("QPushButton") and evt.type() == QEvent.MouseButtonPress:
            print("Object: %s" % recevier)
            print("Event: %s" % evt)
        return super().notify(recevier, evt)

class custom_btn(QPushButton):
    def __init__(self):
        super().__init__()

    def event(self, evt):
        if evt.type() == QEvent.MouseButtonPress:
            print("监听了事件哦！")
        return super().event(evt)

    def mousePressEvent(self, evt):
        print("覆盖打印内容")
        # return super().mousePressEvent(evt)

    def timerEvent(self, evt):
        # print("每隔2秒我出现一次哦~")
        pass

app = App(sys.argv)
window = QWidget()
window.resize(500, 500)

def press():
    print("按钮被点击了！")

btn = custom_btn()
btn.setParent(window)
btn.setText("Enter")
btn.resize(100, 50)
btn.move(250, 250)
btn.pressed.connect(press)
btn_timer = btn.startTimer(2000, Qt.PreciseTimer)


window.show()
sys.exit(app.exec_())